<template>
  <s-modal title="新增" :visible="visible" width="800px" ok-text="保存" :confirm-loading="confirmLoading"
    :closable="!confirmLoading" @ok="save()" @cancel="() => { if (!confirmLoading) { visible = false } }">
    <div style="height:400px">
      <s-scroll>
        <s-form ref="form" :value="formValue">
          <s-form-item label="订阅人" size="middle" name="userId" :colon="true" :display-title="true"
            :rules="[{ 'max': 50, 'message': '最长为50位' }]">
            <s-input :allow-clear="true" placeholder="请输入订阅人" v-model="formValue.userId" />
          </s-form-item>
          <s-form-item label="订阅ID" size="middle" name="subId" :colon="true" :display-title="true"
            :rules="[{ 'max': 50, 'message': '最长为50位' }]">
            <s-input :allow-clear="true" placeholder="请输入订阅ID" v-model="formValue.subId" />
          </s-form-item>
          <s-form-item label="订阅部门" size="middle" name="deptId" :colon="true" :display-title="true"
            :rules="[{ 'max': 50, 'message': '最长为50位' }]">
            <s-input :allow-clear="true" placeholder="请输入订阅部门" v-model="formValue.deptId" />
          </s-form-item>
          <s-form-item label="订阅类型" size="middle" name="typeId" :colon="true" :display-title="true"
            :rules="[{ 'max': 50, 'message': '最长为50位' }]">
            <s-input :allow-clear="true" placeholder="请输入订阅类型" v-model="formValue.typeId" />
          </s-form-item>
          <s-form-item label="订阅类型详情" size="middle" name="dataType" :colon="true" :display-title="true"
            :rules="[{ 'max': 10, 'message': '最长为10位' }]">
            <s-input :allow-clear="true" placeholder="请输入订阅类型详情" v-model="formValue.dataType" />
          </s-form-item>

        </s-form>
      </s-scroll>
    </div>
  </s-modal>
</template>

<script>

export default {
  name: 'Add',
  emits: ['change'],
  data() {
    return {
      formValue: {},
      confirmLoading: false,
      visible: false
    }
  },
  methods: {
    open() {
      this.formValue = {}
      this.visible = true
    },
    save() {
      const _this = this
      const form = this.$refs.form
      form.validate((values, fullValue) => {

        this.confirmLoading = true
        this.$api.PUT('/modules/subscribeInfo/insert', values).then(res => {
          this.confirmLoading = false
          this.visible = false
          this.$emit('success');
          this.$message.info(res.msg)
        }).catch(() => {
          this.confirmLoading = false
        })
      })
    }
  }
}
</script>

<style lang="less" scoped></style>